<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let socket = new WebSocket("ws://81.70.149.16:9999?username=mxd&password=mi191919");

        // let socket = new WebSocket("ws://127.0.0.1:80/ws/123?req=ok");

        socket.onopen = function(event) {
            console.log("连接成功")
            let toSend = "{" +
                "   \"id\": \"123456\"," +
                "   \"from\": \"mxd\"," +
                "   \"to\": \"mxd888\"," +
                "   \"cmd\":\"11\"," +
                "   \"createTime\": \"1581694789\"," +
                "   \"msgType\": \"0\"," +
                "   \"chatType\":\"1\"," +
                "   \"groupId\":\"100\"," +
                "   \"content\": \"群里聊天消息\"" +

                "}"

            socket.send(toSend)
            // "   \"extras\" : \"{'name':'value'}\"" +


        }

        socket.onmessage = function(msg) {
            console.log(msg.data)

        }



        socket.onerror = function(msg) {
            console.log("出错")
        }

        socket.onclose = function(event) {
            console.log('关闭')
        }
    </script>
</body>

</html>